package org.peterbjornx.io;

import org.peterbjornx.cypher.ISAACRandom;

import java.io.DataOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.ByteArrayOutputStream;

/**
 * Created by IntelliJ IDEA.
 * User: PeterbjornX
 * Date: Apr 8, 2009
 * Time: 6:07:29 PM
 * >
 */
public class RSOutputStream extends DataOutputStream {

    /**
     * Creates a new data output stream to write data to the specified
     * underlying output stream. The counter <code>written</code> is
     * set to zero.
     *
     * @param out the underlying output stream, to be saved for later
     *            use.
     * @see java.io.FilterOutputStream#out
     */
    public RSOutputStream(OutputStream out) {
        super(out);
    }

    public void writeString10T(String s) throws IOException {
        writeBytes(s);
        writeByte(10);
    }

    public int getWritten() {
        return written;
    }

    private ISAACRandom isaac;

    public void writeISAACByte(int val) throws IOException {
        int is =isaac.val();
        write((byte)(val+is));
    }

    public void initISAACCypher(int[] seed){
        isaac = new ISAACRandom(seed);
    }

    public void writeBytes_reverseA(byte d[],int off,int len) throws IOException {
        for (int i = (off + len) - 1;i >= off;i--){
            write(d[i]+128);
        }
    }
    public void writeBytes_reverse(byte abyte0[], int i, int j) throws IOException {
        for (int k = (j + i) - 1; k >= j; k--)
			write(abyte0[k]);

	}
    public void set(OutputStream byteout) {
       out = byteout;
    }
}
